package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.TemplateTableRelVo;
import com.ruoyi.system.service.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务模板-业务数据关联Controller
 *
 * @author chenming
 * @date 2024-10-16
 */
@RestController
@RequestMapping("/system/templateTableRel")
public class TemplateTableRelController extends BaseController
{
    @Autowired
    private ITemplateTableRelService templateTableRelService;

    /**
     * 查询业务模板-业务数据关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TemplateTableRel templateTableRel)
    {
        startPage();
        List<TemplateTableRelVo> list = templateTableRelService.selectTemplateTableRelList(templateTableRel);
        return getDataTable(list);
    }

    /**
     * 导出业务模板-业务数据关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:export')")
    @Log(title = "业务模板-业务数据关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TemplateTableRel templateTableRel)
    {
        List<TemplateTableRelVo> list = templateTableRelService.selectTemplateTableRelList(templateTableRel);
        ExcelUtil<TemplateTableRelVo> util = new ExcelUtil<TemplateTableRelVo>(TemplateTableRelVo.class);
        util.exportExcel(response, list, "业务模板-业务数据关联数据");
    }

    /**
     * 获取业务模板-业务数据关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long relId)
    {
        return success(templateTableRelService.selectTemplateTableRelByTemplateId(relId));
    }

    /**
     * 新增业务模板-业务数据关联
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:add')")
    @Log(title = "业务模板-业务数据关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TemplateTableRel templateTableRel)
    {
        return toAjax(templateTableRelService.insertTemplateTableRel(templateTableRel));
    }

    /**
     * 修改业务模板-业务数据关联
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:edit')")
    @Log(title = "业务模板-业务数据关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TemplateTableRel templateTableRel)
    {
        return toAjax(templateTableRelService.updateTemplateTableRel(templateTableRel));
    }

    /**
     * 删除业务模板-业务数据关联
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:remove')")
    @Log(title = "业务模板-业务数据关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] relIds)
    {
        return toAjax(templateTableRelService.deleteTemplateTableRelByTemplateIds(relIds));
    }

    /**
     * 业务表关联
     */
    @PreAuthorize("@ss.hasPermi('system:templateTableRel:edit')")
    @Log(title = "业务模板-业务数据关联", businessType = BusinessType.UPDATE)
    @PostMapping("/editRelation")
    public AjaxResult editRelation(@RequestBody List<TemplateTableRel> tableRelList)
    {
        return toAjax(templateTableRelService.updateTemRel(tableRelList));
    }

}
